<template>
	<view class="my-settle-container">
		<!-- 全选 -->
		<label class="radio" @click="changeAllGoodsState">
			<radio color="#C00000" :checked="isFullCheck"><text>全选</text></radio>
		</label>
		<!-- 合计 -->
		<view class="amount-box">
			合计：<text class="amount">￥{{checkedGoodsAmount}}</text>
		</view>
		<!-- 结算 -->
		<view class="btn-settle" @click="settlement">
			结算（{{checkedCount}}）
		</view>
	</view>
</template>

<script>
	import {mapGetters,mapMutations,mapState} from 'vuex'
	export default {
		name:"my_settle",
		data() {
			return {
				seconde:3,
				time:null
			};
		},
		computed:{
			...mapState('my_user',['token']),
			...mapGetters('my_cart',['checkedCount','total','checkedGoodsAmount']),
			...mapGetters('my_user',['addstr']),
			isFullCheck(){
				return this.total===this.checkedCount
			}
		},
		methods:{
			...mapMutations('my_cart',['updateAllGoodsState']),
			changeAllGoodsState(){
				this.updateAllGoodsState(!this.isFullCheck)
			},
			settlement(){
				if(!this.checkedCount) return uni.$showMsg('请选择结算商品')
				if(!this.addstr) return uni.$showMsg('请选择收或地址')
				if(!this.token) return this.delayNavigate()
			},
			delayNavigate(){
				this.seconde=3
				this.showTip(this.seconde)
				this.time=setInterval(()=>{
					this.seconde--
					if(this.seconde<=0){
						clearInterval(this.time)
						uni.switchTab({
							url:'/pages/my/my'
						})
						return
					}
					this.showTip(this.seconde)
				},1000)
			},
			showTip(n){
				uni.showToast({
					icon:'none',
					title:'请先登录再结算！'+n+'秒之后自动跳转到登录页面',
					mask:true,
					duration:1500
				})
			}
		}
	}
</script>

<style lang="scss">
	.my-settle-container{
		position: fixed;
		bottom: 0;
		left:0;
		width: 100%;
		height: 50px;
		background-color: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 14px;
		padding-left:5px ;
		.radio{
			display: flex;
			align-items: center;
		}
		.amount-box{
			.amount{
				color: #c00000;
				font-weight: bold;
			}
		}
		.btn-settle{
			background-color: #c00000;
			height: 50px;
			color: white;
			line-height: 50px;
			padding: 0 10px;
			min-width: 100px;
			text-align: center;
		}
	}
</style>